package com.ruoyi.core.service.impl;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.core.domain.ServerConfig;
import com.ruoyi.core.mapper.ServerConfigMapper;
import com.ruoyi.core.service.ServerConfigService;
import io.jsonwebtoken.lang.Assert;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class ServerConfigServerImpl implements ServerConfigService {

    @Autowired
    private ServerConfigMapper serverConfigMapper;

    @Override
    public TableDataInfo getServerList() {
        return new TableDataInfo(serverConfigMapper.selectAllList());
    }

    @Override
    public void enableServer(Long id) {
        ServerConfig serverConfig = serverConfigMapper.selectByPrimaryKey(id);
        Assert.notNull(serverConfig,"不存在的服务器");
        serverConfigMapper.updateAllDisabled();
        serverConfig.setStatus(1);
        serverConfigMapper.updateByPrimaryKey(serverConfig);
    }

    @Override
    public ServerConfig getAvailableNode() {
        return serverConfigMapper.selectAvailableNode();
    }
}
